package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"homepage_srv/homepage"
	"homepage_srv/internal/dao"
	"homepage_srv/internal/svc"
	"smart-health-platforms/pkg"
)

type GoodDetailLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodDetailLogic {
	return &GoodDetailLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 商品详情
func (l *GoodDetailLogic) GoodDetail(in *homepage.GoodDetailRequest) (*homepage.GoodDetailResponse, error) {
	good, err := dao.GetGoodDetail(in)
	if err != nil {
		pkg.Warn("商品信息查询失败")
		return nil, err
	}
	pkg.Warn("商品详情查询成功")
	return &homepage.GoodDetailResponse{
		Id:            good.Id,
		BrandId:       uint64(good.BrandId),
		MainImage:     good.MainImage,
		SliderImageId: uint64(good.SliderImageId),
		StoreName:     good.StoreName,
		Hot:           uint64(good.Hot),
		Sales:         uint64(good.Sales),
		StoreInfo:     good.StoreInfo,
		CateId:        uint64(good.CateId),
	}, nil
}
